package com.sharing.library.config;


import static com.google.common.base.Predicates.or;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import springfox.documentation.builders.ApiInfoBuilder;
import springfox.documentation.builders.RequestHandlerSelectors;
import springfox.documentation.service.ApiInfo;
import springfox.documentation.spi.DocumentationType;
import springfox.documentation.spring.web.plugins.Docket;
import springfox.documentation.swagger2.annotations.EnableSwagger2;

import static springfox.documentation.builders.PathSelectors.regex;

/**
 *
 * @author zhx
 * @create 2018-02-09 14:11
 **/
@Configuration
@EnableSwagger2
public class SwaggerConfigLibraryBack {
    @Bean
    public Docket createowl2livingApi() {
        return new Docket(DocumentationType.SWAGGER_2)
                .groupName("sharing 图书馆 后台接口")
                .apiInfo(apiInfo())
                .select()
                .apis(RequestHandlerSelectors.basePackage("com.sharing.library.controller"))
                .apis(RequestHandlerSelectors.withClassAnnotation(Api.class))
                .apis(RequestHandlerSelectors.withMethodAnnotation(ApiOperation.class))
                //.paths(PathSelectors.any())
                .paths(or(regex("/.*")))//过滤的接口
                .build();
    }

    private ApiInfo apiInfo() {
        return new ApiInfoBuilder()
                .title("使用Swagger2构建RESTful API")
                .description("")
                .termsOfServiceUrl("")
                .contact("北京理工")
                .version("1.0")
                .build();
    }
}
